package top.ezzz.config;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.solon.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.solon.plugins.inner.PaginationInnerInterceptor;
import com.zaxxer.hikari.HikariDataSource;
import lombok.extern.slf4j.Slf4j;
import org.noear.solon.annotation.Bean;
import org.noear.solon.annotation.Configuration;
import org.noear.solon.annotation.Init;
import org.noear.solon.annotation.Inject;

import javax.sql.DataSource;


//配置数据源
@Slf4j
@Configuration
public class DataSourceConfig {


    @Bean(name = "db1", typed = true)
    public DataSource db1(@Inject("${chat.db1}") HikariDataSource ds) {
        return ds;
    }

    /**
     * 添加分页插件
     */
    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor() {
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        // 如果配置多个插件,切记分页最后添加
        interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.SQLITE));
        // 如果有多数据源可以不配具体类型 否则都建议配上具体的DbType
        // interceptor.addInnerInterceptor(new PaginationInnerInterceptor());
        return interceptor;
    }

    @Init
    public void initConfig() {
    }


}